package com.mdinfo.gw.door.mapper

import com.baomidou.mybatisplus.mapper.BaseMapper
import com.mdinfo.gw.door.bean.DoorCard
import com.mdinfo.gw.door.bean.DoorCardTimeBind
import org.apache.ibatis.annotations.Delete
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select

/**
 * Created by Administrator on 2018/2/8.
 */
interface DoorCardTimeBindMapper : BaseMapper<DoorCardTimeBind>{

    /**根据开放时间删除*/
    @Delete("""<script>
        delete from door_card_time_bind where timeId = #{timeId}
    </script>""")
    fun delByTimeId(timeId:Int)

    /**根据开放时间id查询*/
    @Select("""<script>
        select * from door_card_time_bind where timeId = #{timeId}
    </script>""")
    fun listByTimeId(timeId:Int):List<DoorCardTimeBind>

    /**根据门id分页查询绑定的门卡*/
    @Select("""<script>
        select b.* from door_card_time_bind b
        join door_open_time t on
        (b.timeId = t.id  and t.doorId = #{doorId})
        order by b.createTime desc
        limit #{start},#{num}
    </script>""")
    fun listByDoorId(@Param("doorId")doorId:Int,
                     @Param("start")start:Int,
                     @Param("num")num:Int)
            :List<DoorCardTimeBind>


    /**根据门id分页查询绑定的门卡 - 总数*/
    @Select("""<script>
        select count(1) from door_card_time_bind b
        join door_open_time t on
        (b.timeId = t.id  and t.doorId = #{doorId})
    </script>""")
    fun countListByDoorId(@Param("doorId")doorId:Int)
            :Int


    /**
     * 根据门卡id查询
     */
    @Select("""<script>
        select * from door_card_time_bind t where t.cardId = #{cardId}
    </script>""")
    fun listByCardId(@Param("cardId")cardId:Int)
            :List<DoorCardTimeBind>

}